{
	template:`
	<a-page-header title="选择用户">
		<template #extra>
			<a-button v-if="!isRadio" type="primary" @click="doManySelect();">选择</a-button>
			<m-back @click="back(false);">关闭</m-back>
		</template>
		<a-card :bodyStyle="{padding:'0 20px'}" :hoverable="true">
		    <div v-if="isRadio">
                <a-input-search v-model:value="searchTxt" placeholder="搜索... 支持+号和空格查询" enter-button :allowClear="true" style="margin:10px 0;" @search="searchAdmin(10)"/>
                <div style="max-height:550px;overflow-y:auto;overflow-x:hidden;">
                    <a-list size="small">
                        <template v-for="item in showUser">
                            <a-list-item>
                                <div>
                                    <span style="min-width:120px;display:inline-block;">
                                        {{item.realname}}
                                    </span>
                                    <a-tag style="margin:3px 0 3px 6px;" v-for="group in userGroups[item.oid]" :color="group.type=='B'?'success':'processing'">{{group.parent.oid?group.parent.name+'/':''}}{{group.name}}</a-tag>
                                </div>
                                <div>
                                    <a-button :disabled="selectMap[item.oid]" size="small" type="primary" @click="doOneSelect(item);">{{selectMap[item.oid]?'已选':'选择'}}</a-button>
                                </div>
                            </a-list-item>
                        </template>
                        <a-list-item v-if="loadNum>maxNum">
                            <div></div>
                            <a-typography-link @click="searchAdmin(maxNum+10)">加载更多...</a-typography-link>
                        </a-list-item>
                        <a-list-item v-if="showUser.length==0">
                            暂无用户
                        </a-list-item>
                    </a-list>
                </div>
			</div>
			<a-row v-else>
				<a-col :span="20">
				    <a-input-search v-model:value="searchTxt" placeholder="搜索... 支持+号和空格查询" enter-button :allowClear="true" style="margin:10px 0;" @search="searchAdmin(10)"/>
					<div style="max-height:550px;overflow-y:auto;overflow-x:hidden;">
						<a-list size="small">
							<template v-for="item in showUser">
								<a-list-item>
									<a-checkbox v-model:checked="selectMap[item.oid]">
										<span style="min-width:120px;display:inline-block;">
											{{item.realname}}
										</span>
										<a-tag style="margin:3px 0 3px 6px;" v-for="group in userGroups[item.oid]" :color="group.type=='B'?'success':'processing'">{{group.parent.oid?group.parent.name+'/':''}}{{group.name}}</a-tag>
									</a-checkbox>
								</a-list-item>
							</template>
                            <a-list-item v-if="loadNum>maxNum">
                                <div></div>
                                <a-typography-link @click="searchAdmin(maxNum+10)">加载更多...</a-typography-link>
                            </a-list-item>
							<a-list-item v-if="showUser.length==0">
								暂无用户
							</a-list-item>
						</a-list>
					</div>
				</a-col>
				<a-col :span="4">
					<div style="max-height:500px;overflow-y:auto;overflow-x:hidden;">
						<div style="padding-top:10px;padding-left:10px;"><b>已选:</b></div>
						<template v-for="item in allUser">
						<a-tag style="margin:10px 0 0 10px;" v-if="selectMap[item.oid]" color="blue" closable @close="removeSelect(item.oid)">{{item.realname}}</a-tag>
						</template>
					</div>
				</a-col>
			</a-row>
		</a-card>
	</a-page-header>
	`,
	props: ['localeZh','param','parentVue'],
	data:function(){
		return {
			isRadio:false,
			orgGroup:'',
			roleGroup:'',
			selected:[],
			searchTxt:'',
			loadNum:0,
            maxNum:10,
			allUser:{},
			showUser:[],
			userGroups:{},
			selectMap:{},
		};
	},
	mounted(){
		this.isRadio=this.param.isRadio;
		this.orgGroup=this.param.orgGroup;
		this.roleGroup=this.param.roleGroup;
		this.selected=this.param.selected;
		this.requestData("action/manage/pageUtil/getAdminLink",
			{orgGroup:this.orgGroup,roleGroup:this.roleGroup},
			function(data){
				if(data.code==0){
					for(var i=0;i<data.list.length;i++){
						var link=data.list[i];
						if(!this.allUser[link.admin.oid]){
							this.allUser[link.admin.oid]=link.admin;
							this.userGroups[link.admin.oid]=[];
							for(var n=0;n<this.selected.length;n++){
								if(this.selected[n].oid==link.admin.oid){
									this.selectMap[link.admin.oid]=true;
								}
							}
						}
						this.userGroups[link.admin.oid].push(link.adminGroup);
					}
					this.searchAdmin(this.maxNum);
				}else{
					this.remind().error(data.msg);
				}
			}.bind(this)
		);
	},
	methods:{
		removeSelect:function(oid){
			this.selectMap[oid]=false;
		},
		searchAdmin:function(max){
		    this.showUser=[];
		    this.loadNum=0;
		    this.maxNum=max;
		    for(let k in this.allUser){
		        if(this.loadNum>max) break;
		        if(this.isShowRow(this.allUser[k])){
		            this.showUser.push(this.allUser[k]);
		            this.loadNum++;
		        }
		    }
		},
		isShowRow:function(item){
			if(!this.searchTxt) return true;
			var array=this.searchTxt.split(/\s+/);
			var flag=false;
			for(let n=0;n<array.length;n++){
			    var arr=array[n].split(/\++/);
			    var b=true;
			    for(let m=0;m<arr.length;m++){
			        var x=false;
                    if(item.realname.indexOf(arr[m])>=0){
                        if(!x){ x=true; }
                    }
                    for(var i=0;i<this.userGroups[item.oid].length;i++){
                        var group=this.userGroups[item.oid][i];
                        if(group.name.indexOf(arr[m])>=0
                                ||group.parent.oid&&group.parent.name.indexOf(arr[m])>=0){
                            if(!x){ x=true;break; }
                        }
                    }
                    if(b&&!x){ b=false;break; }
			    }
			    if(b) flag=true;
			}
			return flag;
		},
		doManySelect:function(){
			var arr=[];
			for(var k in this.selectMap){
				arr.push(this.allUser[k]);
			}
			this.back(true,arr);
		},
		doOneSelect:function(item){
			this.back(true,[item]);
		},
	}
}